/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mx.itschapala.dsw2.vista;

import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.event.ActionEvent;
import mx.itschapala.dsw2.bar.bl.InventarioBlLocal;
import mx.itschapala.dsw2.bar.modelo.Inventario;

/**
 *
 * @author Dhavis
 */
@ManagedBean
@SessionScoped
public class InventarioBean {
    //---------------EJB'S-------------------------

    @EJB
    private InventarioBlLocal inventarioBl;
    //------------------variables(propiedades)--------------
    private List<Inventario> listin;
    private Inventario inventario;
    private String accion;

    /**
     * Creates a new instance of Inventario
     */
    //-----------constructor--------------------------------
    public InventarioBean() {
        inventario = new Inventario();
        
    }
    //-----------metodos GET y SET--------------------------------

    public List<Inventario> getListin() {
        listin = inventarioBl.getListin();
        return listin;
    }

    public Inventario getInventario() {
        return inventario;
    }

    public void setInventario(Inventario inventario) {
        this.inventario = inventario;
    }
    //-----------Acciones--------------------------------

    public String procesarInventario() {
        if (accion.equalsIgnoreCase("Nuevo")) {
        }
        accion = "";
        return "InventarioVista";
    }
    //-----------Listeners--------------------------------  

    public void prepararInventario(ActionEvent evt) {//accionEvent de faces
        inventario = new Inventario();
        accion = "Nuevo";
    }

    public void editarInventario(ActionEvent evt) {
        System.out.println(evt.getComponent().getClientId());
        String arr[] = evt.getComponent().getClientId().split(":");
        String num = arr[3];
        int index = Integer.parseInt(num);
        System.out.println("el numero es: " + index);
        // loan=lista.get(index);
        accion = "Editar";
    }

    public void prepararEliminar(ActionEvent evt) {
        String arr[] = evt.getComponent().getClientId().split(":");
        String num = arr[3];
        int index = Integer.parseInt(num);
        System.out.println("el numero es: " + index);
        //loan=lista.get(index);
        accion = "Eliminar";
    }
    public void eliminar(ActionEvent evt) {
        String arr[] = evt.getComponent().getClientId().split(":");
        String num = arr[2];
        int index = Integer.parseInt(num);
        System.out.println("el numero es: " + index);
        listin.remove(index);
    }
    
    public void procesarSeleccion(ActionEvent evt){
//        inventario.setIdusuario(inventarioBl.register(null);
    }//<editor-fold defaultstate="collapsed" desc="comment">
    
    //</editor-fold>
}
